new Vue({
    el: '#cele',
    data: {
        time: '',
        flag:'',
        fire_num:'2',   //火灾个数
        FireNumer:'',//火灾编号
        g_fire_num:'3',   //火灾更新个数
        DDZB_name:'',           // 大队值班
        ZZZB_name:[],           //中队值班
        ZBWY_name:'',           //值班文员
        ZBCM_name:'',           // 值班参谋
        lookchat:[],
        tableData: [{
            date: '2016-05-02',
            num: '01',
            msg: '上海市普陀区金沙江路 1518 弄'
        }, {
            date: '2016-05-04',
            num: '02',
            msg: '上海市普陀区金沙江路 1517 弄'
        }, {
            date: '2016-05-01',
            num: '03',
            msg: '上海市普陀区金沙江路 1519 弄'
        }, {
            date: '2016-05-03',
            num: '04',
            msg: '上海市普陀区金沙江路 1516 弄'
        }],
        water_car:[],
        bottom_num:4,
        ZBLD_name:'韩瑶',
        WQ_name:'瑶瑶',
        NQ_name:'瑶瑶瑶',
        FireManInfoModel:{},
        UserRoleRelationModel:{},
        PutProceed:'0',
        SetVehicle:[],
        GetPeople:"",
        VehicleClass:[],
        ProceedFire:"0",
        ZNPeople:'',
        TNPeople:'',
        ZWLPeople:'',
        TWPeople:''
    },
    mounted() {
        debugger
        console.log(Url)
        //var Vue = thi
        // s
        //var  _FireManInfoModel={},_UserRoleRelationModel={}
        //var c = $.cookie('token')
        //debugger
        //if (c == '' || c == undefined) {
        //    //  token 如果等于空 返回登陆页
        //    window.location.href = '../login.html'
        //} else {
            var _Vue = this
            setInterval(function () {
                var time = new Date();
                var y = time.getFullYear();
                var m = time.getMonth() + 1;
                var d = time.getDate();
                var h = time.getHours();
                var mm = time.getMinutes();
                var s = time.getSeconds();
                _Vue.time = y + '年' + _Vue.add0(m) + '月' + _Vue.add0(d) + '日  ' + _Vue.add0(h) + ':' + _Vue.add0(mm) + ':' + _Vue.add0(s);
            }, 1000)

            $('.main-left-bj ul li a').click(function () {
                //console.log(this)
                $(this).find('span').toggleClass('glyphicon-plus glyphicon-minus yellow-text')
            });
            //  存储信息
            _Vue.FireManInfoModel = $.parseJSON(localStorage.getItem('msg'));
            console.log(_Vue.FireManInfoModel)
            _Vue.UserRoleRelationModel = $.parseJSON(localStorage.getItem('item'));
            var a =  _Vue.FireManInfoModel;
            var b = _Vue.UserRoleRelationModel;

        this.init(a, b)
        //}
        this.ajaxProceedFire;//获取正在进行的火灾信息
        this.ajaxPutProceed;//获取当天扑救和正在扑救的火灾信息
        this.ajaxSetVehicle();//获取可以出动的车辆
        this.ajaxGetPeople()//获取指挥员、通讯员的排班信息
        this.ajaxVehicleClass()//获取车辆排班信息

    },
    computed:{
        //获取正在进行的火灾信息
        ajaxProceedFire(){
            var Vue = this;
            debugger
            //console.log(this.FireManInfoModel)
            Vue.openLoading()
            $.ajax({
                type: 'post',
                url: Url+'FireInfoApi/GetNoFinishFireInfoList',
                data: JSON.stringify({ ChargeNumber: this.FireManInfoModel.Fire_brigade_num }),//中队编号
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    debugger
                    //console.log(this.FireManInfoModel)
                    console.log(msg)
                    Vue.closeLoading()
                    function count(o){
                        var t = typeof o;
                        if(t == 'string'){
                            return o.length;
                        }else if(t == 'object'){
                            var n = 0;
                            for(var i in o){
                                n++;
                            }
                            return n;
                        }
                    }
                    if (msg.state == 1) {
                        debugger
                        Vue.ProceedFire =  count(msg.data);
                    }else {
                        Vue.ProceedFire =  0;
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Vue.closeLoading()
                    //console.log(XMLHttpRequest, textStatus, errorThrown)
                }
            });
        },
        //获取当天扑救和正在扑救的火灾信息
        ajaxPutProceed(){
            var Vue = this;
            Vue.openLoading()
            $.ajax({
                type: 'post',
                url: Url+'FireInfoApi/GetTodayFireInfoList',
                data: JSON.stringify({ ChargeNumber: this.FireManInfoModel.Fire_brigade_num }),//中队编号
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    console.log(msg.data)
                    function count(o){
                        var t = typeof o;
                        if(t == 'string'){
                            return o.length;
                        }else if(t == 'object'){
                            var n = 0;
                            for(var i in o){
                                n++;
                            }
                            return n;
                        }
                        return false;
                    }
                    Vue.closeLoading()
                    debugger
                    Vue.lookchat =msg.data
                    if (msg.state == 1) {
                        Vue.PutProceed = count(msg.data);//数字
                    }else {
                        Vue.PutProceed = 0;//数字
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Vue.closeLoading()
                    console.log(XMLHttpRequest, textStatus, errorThrown)
                }
            });
        },


    },
    methods:{
        //获取可以出动的车辆
        ajaxSetVehicle(){
            var Vue = this;
            //debugger
            Vue.openLoading()
            $.ajax({
                type: 'post',
                url: Url+'VehicleInfoApi/GetVehicleInfoBrigadeCanUseList',
                data: JSON.stringify({ BrigadeNumber: this.FireManInfoModel.Fire_brigade_num }),//中队编号
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    //console.log(msg)
                    Vue.closeLoading()
                    if (msg.state == 1) {
                        Vue.SetVehicle = msg.data;
                    }else {

                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Vue.closeLoading()
                    console.log(XMLHttpRequest, textStatus, errorThrown)
                }
            });
        },

        //获取指挥员、通讯员的排班信息
        ajaxGetPeople(){
            var Vue = this;
            //debugger
            //console.log(Vue.FireNumer)
            Vue.openLoading()
            $.ajax({
                type: 'post',
                url: Url+'NormalDutyApi/GetNormalCommanderDutyInfoList',
                data: JSON.stringify({ BrigadeNumber: this.FireManInfoModel.Fire_brigade_num  }),//中队编号
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    console.log(msg.data)
                    Vue.closeLoading()
                    if (msg.state == 1) {
                        debugger;
                        console.log(msg.state)
                        Vue.People_msg(msg)
                        //Vue.GetPeople = msg.data;
                    }else {

                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Vue.closeLoading()
                    console.log(XMLHttpRequest, textStatus, errorThrown)
                }
            });
        },
//获取车辆排班信息
        ajaxVehicleClass(){
            var Vue = this;
            Vue.openLoading()
            $.ajax({
                type: 'post',
                url: Url+'NormalDutyApi/GetNormalVehicleDutyInfo',
                data: JSON.stringify({ FireNumber: Vue.FireNumer,BrigadeNumber: this.FireManInfoModel.Fire_brigade_num }),//火灾编号//中队编号
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    Vue.closeLoading()
                    if (msg.state == 1) {
                        debugger
                        Vue.VehicleClass = msg.data;
                    }else {

                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Vue.closeLoading()
                    console.log(XMLHttpRequest, textStatus, errorThrown)
                }
            });
        },


        add0(m){
            return m<10?'0'+m:m
        },
        init(a,b) {
        //console.log(a)
            $('#item_id').html(a.Fire_brigade_name)
        },
        newOpen(){
            window.open("fire_first.html")
        },
        Toupdate(){
            debugger
            var ProceedVal = this.PutProceed
            if(ProceedVal==1){
                var id =this.lookchat[0].Number
                window.open("fire_second.html?FireNumer="+id)
                //window.location.href='./fire_first.html'
            }else if(ProceedVal>1){
                this.flag ='1'
                debugger
                console.log(this.lookchat)
            }else {
                this.$message({
                    message: '当前没有火灾险情。',
                    type: 'success'
                });
            }
        },
        gb(){
            this.flag =''
        },
        goin(index){
            debugger
            var id= index
            var Vue = this;
            window.open("fire_second.html?FireNumer="+id)
            Vue.openLoading()
            FireNumber: Vue.FireNumer

        },
        Quit(){
            $.cookie('token', '',{ expires: -1 ,path: '/' });
            window.location.href='../login.html'
        },
        openLoading() {
            //console.log('loading')
            this.loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
        },
        closeLoading(){
            //console.log('no')
            this.loading.close();
        },

        People_msg(msg){
            var Vue = this
            for(var i =0;i<msg.data.length;i++){
                debugger
                if(msg.data[i].Commander_duty == '1'&&msg.data[i].Commander_type=='1'){
                    Vue.ZNPeople = msg.data[i].Commander_name
                }else if(msg.data[i].Commander_duty == '2'&& msg.data[i].Commander_type=='1'){
                    Vue.TNPeople = msg.data[i].Commander_name
                }else if(msg.data[i].Commander_duty == '1'&& msg.data[i].Commander_type=='2'){
                    Vue.ZWLPeople = msg.data[i].Commander_name
                }else {
                    Vue.TWPeople = msg.data[i].Commander_name
                }
            }

        }
    }

})
